
/*
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


#include <stdio.h>
#include <string.h>

#include "libmooigraph.h"
#include "lmg.h"

struct lmgnode *
lmg_uniqn (char *name)
{
  lmgsplay_tree_node spn = NULL;

  if (lmgnodes == NULL)
    {
      lmgnodes =
	lmgsplay_tree_new (lmgsplay_tree_compare_strings, NULL, NULL);
    }
  spn = lmgsplay_tree_lookup (lmgnodes, (lmgsplay_tree_key) name);
  if (spn)
    {
      return ((struct lmgnode *) spn->value);
    }
  else
    {
      return (NULL);
    }
}

void
lmg_uniqnadd (char *name, struct lmgnode *node)
{
  lmgsplay_tree_node spn = NULL;

  if (lmgnodes == NULL)
    {
      lmgnodes =
	lmgsplay_tree_new (lmgsplay_tree_compare_strings, NULL, NULL);
    }
  spn = lmgsplay_tree_lookup (lmgnodes, (lmgsplay_tree_key) name);
  if (spn)
    {
      return;
    }
  lmgsplay_tree_insert (lmgnodes, (lmgsplay_tree_key) name,
			(lmgsplay_tree_value) node);

  return;
}

void
lmg_uniqnclear (void)
{
  if (lmgnodes)
    {
      lmgsplay_tree_delete (lmgnodes);
      lmgnodes = NULL;
    }
  return;
}

/* End */
